//获取应用实例
const app = getApp()
const api = require('../../Datas/api.js');
function getRandomColor() {
  let rgb = []
  for (let i = 0; i < 3; ++i) {
    let color = Math.floor(Math.random() * 256).toString(16)
    color = color.length == 1 ? '0' + color : color
    rgb.push(color)
  }
  return '#' + rgb.join('')
}

Page({
  data: {
   id:0,
   data:{} 
  },
  onReady: function (res) {
    this.videoContext = wx.createVideoContext('myVideo')
  },
  inputValue: '',
  data: {
    evaluate:"",
    userInfo: {},
    src: '',
  },

  onLoad: function (options) {
console.log('--------------------')
    var $this = this;
    app.saveWechatUserInfo(app, function (userInfo) {
      $this.setData({
        userInfo: userInfo,
        hasUserInfo: true
      })

      $this.addWatchHistory(userInfo, options);

      $this.setData({
        id: options.id,
      });

      //$this.getVideoByVid(options.id);
    })

  },

  addWatchHistory: function (userInfo, options){
    let param = {
      API_URL: app.globalData.apiUrl + '/videoData/addWatchHistory',
      method: "POST",
      data: {
        uid: String(userInfo.id),
        vid: String(options.id)
      }
    };

    api.result(param).then(data => {
      let datas = data.data.data;
      console.log(data);
      // this.setData({
      //   searchList: searchList,
      // })

    }).catch(e => {
      console.log(e)
      // this.setData({
      //   loadtxt: '数据加载异常',
      //   loading: false
      // })

    })

  },

  getVideoByVid:function(id){
    let param = {
      API_URL: app.globalData.apiUrl + 'videoData/getVideoByVid',
      method: "GET",
      data: {
        vid: id
      }
    };

    api.result(param).then(data => {
      let datas = data.data.data;
      console.log(data);
      this.setData({
        data: datas,
      })

    }).catch(e => {
      console.log(e)
      // this.setData({
      //   loadtxt: '数据加载异常',
      //   loading: false
      // })

    })
  },


  //评价
  sendEvaluate: function (event){
    console.log(event);
    this.setData({
      evaluate: ''
    })  
    
  }
})